package com.zcf.mappers;//package com.zcf.mappers;
//
//import java.io.File;
//import java.util.Iterator;
//import java.util.List;
//
//import javax.xml.parsers.DocumentBuilder;
//import javax.xml.parsers.DocumentBuilderFactory;
//
//import org.dom4j.Attribute;
//import org.dom4j.Document;
//import org.dom4j.DocumentException;
//import org.dom4j.DocumentHelper;
//import org.dom4j.Element;
//import org.dom4j.io.SAXReader;
//import java.io.File;
//import java.io.FileOutputStream;
//
//import org.dom4j.Document;
//import org.dom4j.DocumentHelper;
//import org.dom4j.Element;
//import org.dom4j.io.OutputFormat;
//import org.dom4j.io.XMLWriter;
//public class Test {
//
////	@SuppressWarnings("unchecked")
////	public static void main(String[] args) throws Exception {
////		String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response><status>1</status><info>OK</info><infocode>10000</infocode><count>1</count><geocodes type=\"list\"><geocode><formatted_address>江西省鹰潭市余江县</formatted_address><country>中国</country><province>江西省</province><citycode>0701</citycode><city>鹰潭市</city><district>余江县</district><township></township><neighborhood><name></name><type></type></neighborhood><building><name></name><type></type></building><adcode>360622</adcode><street></street><number></number><location>116.822763,28.206177</location><level>区县</level></geocode></geocodes></response>";
////		Document document = DocumentHelper.parseText(xml);
////		Element root = document.getRootElement();
////		List<Element> elements = root.elements();
////		for (Iterator<Element> it = elements.iterator(); it.hasNext();) {
////			Element element = it.next();
////			List<Attribute> attributes = element.attributes();
////			for (int i = 0; i < attributes.size(); i++) {
////				Attribute attribute = attributes.get(i);
////				if ("location".equals(attribute.getText())) {
////					System.out.println(element.getName() + "  :  " + element.getText());
////				}
////			}
////		}
////	}
//
////	 public static void main(String[] args) throws Exception {
////	        SAXReader reader = new SAXReader();
////	        File file = new File("books.xml");
////	        Document document = reader.read(file);
////	        Element root = document.getRootElement();
////	        List<Element> childElements = root.elements();
////	        for (Element child : childElements) {
////	            //未知属性名情况下
////	            /*List<Attribute> attributeList = child.attributes();
////	            for (Attribute attr : attributeList) {
////	                System.out.println(attr.getName() + ": " + attr.getValue());
////	            }*/
////
////	            //已知属性名情况下
////	            System.out.println("id: " + child.attributeValue("id"));
////
////	            //未知子元素名情况下
////	            /*List<Element> elementList = child.elements();
////	            for (Element ele : elementList) {
////	                System.out.println(ele.getName() + ": " + ele.getText());
////	            }
////	            System.out.println();*/
////
////	            //已知子元素名的情况下
////	            System.out.println("title" + child.elementText("title"));
////	            System.out.println("author" + child.elementText("author"));
////	            //这行是为了格式化美观而存在
////	            System.out.println();
////	        }
////	    }
//
//
//	public void test(){
//		Long start = System.currentTimeMillis();
//		createXml();
//		System.out.println("运行时间："+ (System.currentTimeMillis() - start));
//	}
//	public static void main(String[] args) throws DocumentException {
////		Long start = System.currentTimeMillis();
////		createXml();
////		System.out.println("运行时间："+ (System.currentTimeMillis() - start));
//
//		SAXReader reader = new SAXReader();
////        File file = new File("books.xml");
//        File file = new File("E:/lp/xml/rss.xml");
//        Document document = reader.read(file);
//        Element root = document.getRootElement();
//        List<Element> childElements = root.elements();
//        for (Element child : childElements) {
//            //未知属性名情况下
//            /*List<Attribute> attributeList = child.attributes();
//            for (Attribute attr : attributeList) {
//                System.out.println(attr.getName() + ": " + attr.getValue());
//            }*/
//
//            //已知属性名情况下
//            System.out.println("id: " + child.attributeValue("id"));
//
//            //未知子元素名情况下
//            /*List<Element> elementList = child.elements();
//            for (Element ele : elementList) {
//                System.out.println(ele.getName() + ": " + ele.getText());
//            }
//            System.out.println();*/
//
//            //已知子元素名的情况下
//            System.out.println("title" + child.elementText("title"));
//            System.out.println("location" + child.elementText("location"));
//            //这行是为了格式化美观而存在
//            System.out.println();
//        }
//	}
//	/**
//	 * 生成xml方法
//	 */
//	public static void createXml(){
//		try {
//			// 1、创建document对象
//			Document document = DocumentHelper.createDocument();
//			// 2、创建根节点rss
//			Element rss = document.addElement("rss");
//			// 3、向rss节点添加version属性
//			rss.addAttribute("version", "2.0");
//			// 4、生成子节点及子节点内容
//			Element channel = rss.addElement("location");
//			Element title = channel.addElement("title");
//			title.setText("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" +
//					"<response>\r\n" +
//					"    <status>1</status>\r\n" +
//					"    <info>OK</info>\r\n" +
//					"    <infocode>10000</infocode>\r\n" +
//					"    <count>1</count>\r\n" +
//					"    <geocodes type=\"list\">\r\n" +
//					"        <geocode>\r\n" +
//					"            <formatted_address>江苏省徐州市铜山区万达</formatted_address>\r\n" +
//					"            <country>中国</country>\r\n" +
//					"            <province>江苏省</province>\r\n" +
//					"            <citycode>0516</citycode>\r\n" +
//					"            <city>徐州市</city>\r\n" +
//					"            <district>铜山区</district>\r\n" +
//					"            <township></township>\r\n" +
//					"            <neighborhood>\r\n" +
//					"                <name></name>\r\n" +
//					"                <type></type>\r\n" +
//					"            </neighborhood>\r\n" +
//					"            <building>\r\n" +
//					"                <name></name>\r\n" +
//					"                <type></type>\r\n" +
//					"            </building>\r\n" +
//					"            <adcode>320312</adcode>\r\n" +
//					"            <street></street>\r\n" +
//					"            <number></number>\r\n" +
//					"            <location>117.188278,34.191573</location>\r\n" +
//					"            <level>兴趣点</level>\r\n" +
//					"        </geocode>\r\n" +
//					"    </geocodes>\r\n" +
//					"</response>");
//			// 5、设置生成xml的格式
//			OutputFormat format = OutputFormat.createPrettyPrint();
//			// 设置编码格式
//			format.setEncoding("UTF-8");
//
//
//			// 6、生成xml文件
//			File file = new File("E:/lp/xml/rss.xml");
//			XMLWriter writer = new XMLWriter(new FileOutputStream(file), format);
//			// 设置是否转义，默认使用转义字符
//			writer.setEscapeText(false);
//			writer.write(document);
//			writer.close();
////			file.delete();
//			System.out.println("生成rss.xml成功");
//		} catch (Exception e) {
//			e.printStackTrace();
//			System.out.println("生成rss.xml失败");
//		}
//	}
//}
